package com.lf.sys.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.lf.sys.mapper.SysLabelMapper;
import com.lf.sys.model.SysLabel;
import com.lf.sys.service.LabelService;

@Service
public class LabelServiceImp implements LabelService {
	private Logger logger = LoggerFactory.getLogger(getClass());

	@Resource
	public SysLabelMapper sysLabelMapper;

	@Override
	public int insert(SysLabel temp) {
		// TODO Auto-generated method stub
		logger.info("class:" + this.getClass().getName() + " method:" + "insert" + " param:" + JSON.toJSONString(temp));
		return sysLabelMapper.insert(temp);
	}

	@Override
	public int delete(long id, long userId) {
		// TODO Auto-generated method stub
		logger.info("class:" + this.getClass().getName() + " method:" + "delete" + " param:" + "id:" + id + "userId:"
				+ userId);
		SysLabel temp = new SysLabel();
		temp.setId(id);
		temp.setUserId(userId);
		return sysLabelMapper.deleteByPrimaryKey(temp);
	}

	@Override
	public int update(SysLabel temp) {
		// TODO Auto-generated method stub
		logger.info("class:" + this.getClass().getName() + " method:" + "update" + " param:" + JSON.toJSONString(temp));
		return sysLabelMapper.updateByPrimaryKey(temp);
	}

	@Override
	public SysLabel get(long id, long userId) {
		// TODO Auto-generated method stub
		logger.info("class:" + this.getClass().getName() + " method:" + "get" + " param:" + "id:" + id + "userId:"
				+ userId);
		SysLabel temp = new SysLabel();
		temp.setId(id);
		temp.setUserId(userId);
		return sysLabelMapper.selectOne(temp);
	}

	@Override
	public List<SysLabel> list(long userId) {
		// TODO Auto-generated method stub
		logger.info("class:" + this.getClass().getName() + " method:" + "list" + " param:" + "userId:" + userId);
		SysLabel temp = new SysLabel();
		temp.setUserId(userId);
		return sysLabelMapper.select(temp);
	}

	@Override
	public SysLabel get(long userId, String labelName) {
		// TODO Auto-generated method stub
		SysLabel temp = new SysLabel();
		temp.setUserId(userId);
		temp.setName(labelName);
		return sysLabelMapper.selectOne(temp);
	}

}
